package com.ux.widget;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.learn.animation.R;

public class BottomMenuItemView {
	
	ViewGroup mContentView;
	TextView uxMenuItemText, uxMenuItemBadge;
	ImageView uxMenuItemIcon;
	View uxMenuItemIconRoot;
	
	private int mId;

	// constructor
	public BottomMenuItemView(Context context, int id) {
		mId = id;
		init(context);
	}
	
	public void setIcon(int resId) {
		uxMenuItemIcon.setImageResource(resId);
	}
	
	public int getId() {
		return mId;
	}
	
	public void setText(String text) {
		uxMenuItemText.setText(text);
	}
	
	/**
	 * 
	 * @param text set null if want to hide this badge
	 */
	public void setBadgeText(String text) {
		if (TextUtils.isEmpty(text)) {
			uxMenuItemBadge.setVisibility(View.GONE);
		} else {
			uxMenuItemBadge.setVisibility(View.VISIBLE);
			uxMenuItemBadge.setText("" + text);
		}
	}
	
//	public void registerOnClickEvent(View.OnClickListener clickListener) {
//		//mContentView.setOnClickListener(clickListener);
//		uxMenuItemIconRoot.setOnClickListener(clickListener);
//	}
	
	public View getIconView() {
		return uxMenuItemIconRoot;
	}
	
	public void setEnableView(boolean enable) {
		uxMenuItemIconRoot.setBackgroundResource(enable ? R.drawable.ux_drawable_bottom_menu_item_background : R.drawable.ux_drawable_bottom_menu_item_pressed);
	}
	
	private void init(Context context) {
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mContentView = (ViewGroup) inflater.inflate(R.layout.ux_bottom_menu_item, null);
		
		uxMenuItemText = (TextView) mContentView.findViewById(R.id.uxMenuItemText);
		uxMenuItemBadge = (TextView) mContentView.findViewById(R.id.uxMenuItemBadge);
		
		uxMenuItemIcon = (ImageView) mContentView.findViewById(R.id.uxMenuItemIcon);
		uxMenuItemIconRoot = mContentView.findViewById(R.id.uxMenuItemIconRoot);
	}
	
	public ViewGroup getView() {
		return mContentView;
	}
	
}
